﻿/**
 * 文字水波波动效果
 * 
 * @USAGE : this.setObj()
 * 			this.startRender();
 * 			this.stopRender();
 */
package  org.nickro.effects
{
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.filters.*;

    public class WaterWave {

        private static var p1:Point;
        private static var warpChannelOptions:Number = 1;
        private static var warpNumOctaves:Number = 2;
        private static var warpBaseY:Number = 200;
        private static var p2:Point;
        private static var _bmpData:BitmapData;
        private static var warpFractalNoise:Boolean = true;
        private static var perlinOffset:Array;
        private static var warpBaseX:Number = 200;
        private static var warpStitch:Boolean = true;
        private static var _obj:DisplayObject;
        private static var warpRandomSeed:Number = (Math.random() * 10);
        private static var warpGrayScale:Boolean = false;

        private static function applyFilter():void{
            p1 = new Point(70, 80);
            p2 = new Point(50, 60);
            perlinOffset = new Array(p1, p2);
        }
        public static function startRender():void{
            _obj.addEventListener(Event.ENTER_FRAME, enterH);
        }
        public static function stopRender():void{
            _obj.removeEventListener(Event.ENTER_FRAME, enterH);
        }
        public static function setObj(_arg1:DisplayObject):void{
            var _local2:Number;
            var _local3:Number;
            _obj = _arg1;
            _local2 = (_arg1.width + 20);
            _local3 = (_arg1.height + 20);
            _bmpData = new BitmapData(_local2, _local3, true, 0);
            _bmpData.draw(_arg1);
            applyFilter();
        }
        private static function enterH(_arg1:Event):void{
            var _local2:DisplacementMapFilter;
            Point(perlinOffset[0]).y = (Point(perlinOffset[0]).y - 2);
            Point(perlinOffset[0]).x = (Point(perlinOffset[0]).x - 2);
            Point(perlinOffset[1]).x = (Point(perlinOffset[1]).x + 2);
            Point(perlinOffset[1]).y = (Point(perlinOffset[1]).y + 2);
            _bmpData.perlinNoise(warpBaseX, warpBaseY, warpNumOctaves, warpRandomSeed, warpStitch, warpFractalNoise, warpChannelOptions, warpGrayScale, perlinOffset);
            _local2 = new DisplacementMapFilter(_bmpData, new Point(0, 0), 1, 1, 20, 20, "color");
            _obj.filters = [_local2];
        }

    }
}//package effect 
